package com.pandora.common.db;

import java.sql.Connection;
import java.sql.SQLException;
import com.alibaba.druid.pool.DruidDataSource;
import com.pandora.common.exception.EduException;
import com.pandora.common.util.CommonUtils;
import com.pandora.common.util.StringUtils;
import com.pandora.framework.util.DBConfig;
import com.pandora.framework.util.LogUtils;

/**
 * 数据源管理
 * 
 * @author JingChenglong 2017/12/25 23:14
 *
 */
public class DBManager {

	private static DruidDataSource druidDataSource = DBConfig.getInstance();

	public static void closeDataSource() {
		// TODO 关闭数据源
	}

	/**
	 * 获取数据源链接
	 * 
	 * @return
	 * @throws EduException
	 */
	public static Connection getConnection() throws EduException {

		Connection connection = null;

		try {
			connection = druidDataSource.getConnection();
		} catch (SQLException e) {
			String errorCode = "C000000001";
			LogUtils.logError(errorCode, CommonUtils.getTraceInfo() + StringUtils.nullToStrTrim(e.getMessage()));
			throw new EduException(errorCode);
		}

		return connection;
	}
}